package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h3>leyou-project</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-05-22 09:22
 **/
@RestController
@RequestMapping("/category")
public class CategoryController {



    @Autowired
    private CategoryService categoryService;

    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryCategoryById(@PathVariable("id") Long id){
        Category category = categoryService.getById(id);
        return ResponseEntity.ok(new CategoryDTO(category));
    }
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam(value = "ids") List<Long> ids){
        List<Category> categories = categoryService.listByIds(ids);
        List<CategoryDTO> categoryDTOS = CategoryDTO.convertEntityList(categories);
        return ResponseEntity.ok(categoryDTOS);
    }
    /**
     *@描述   根据父类目id查询子类目集合
     *@参数  [id]
     *@返回值  org.springframework.http.ResponseEntity<java.util.List<com.leyou.item.dto.CategoryDTO>>
     *@创建人  hhw
     *@创建时间  2020/5/24
     *@修改人和其它信息
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByPId(@RequestParam(value = "pid")Long id){
        List<CategoryDTO> categoryDTO = CategoryDTO.convertEntityList(categoryService.lambdaQuery().eq(Category::getParentId, id).list());
        return ResponseEntity.ok(categoryDTO);

    }

    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBrandId(@RequestParam("id")Long id) {
        return ResponseEntity.ok(CategoryDTO.convertEntityList(categoryService.queryCategoryByBrandId(id)));
        }





}
